const jumpLogin=()=>{
        window.location.href='./login.html'
    }
const li1s=document.querySelectorAll('.nan li')
const line1=document.querySelector('.line1')
const changeSex=()=>{
    div1.innerHTML=''
    div2.innerHTML=''
    ul2.innerHTML=''
    li1s.forEach(item=>{
        item.classList.remove('liActive')
    })
    event.target.classList.add('liActive')
    if(event.target.dataset.index==0){
        
        line1.style.left='0'
        changeContentMan(0)
        getList(0,0)
    }else{
        line1.style.left='100px'
        changeContentMan(1)
        getList(1,1)
        console.log(111)
    }
}
const div1=document.querySelector('.content-sort')
const div2=document.querySelector('.rcul')
const changeContentMan=(e=0)=>{
    fetch(`https://www.zongheng.com/api2/catefine/storeSearchConf?bookType=${e}`).then(res=>res.json()).then(res1=>{
        let total=''
        res1.result.categoryList.list.forEach((item,index)=>{
            if(index==0){
                total+=`
                    <li data-sort="0" onclick="getValue1()" class="li2Active">${item.name}</li>
                `
            }else{
                    total+=`
                        <li data-sort="${item.paramValue}" onclick="getValue1()">${item.name}</li>
                    `
            }
            
        })
        div1.innerHTML+=`
            <div class="everyContent">
                <p class="csT">作品分类</p>
                <ul class="csul csul1">
                    ${total}
                </ul>
            </div>
        `
        res1.result.filtrateTypeList.forEach((item,index)=>{
            if(index==0){
                let allList=''
                item.filtrateOptionList.forEach((items, index1) => {
                    if (index1 == 0) {
                        allList += `
                        <li data-sort="${items.paramValue}" onclick="getValue2()" class="li2Active">${items.name}</li>
                    `
                    } else {
                        allList += `
                        <li data-sort="${items.paramValue}" onclick="getValue2()">${items.name}</li>
                    `
                    }
                })
                div1.innerHTML+=`
                    <div class="everyContent">
                        <p class="csT">${item.name}</p>
                        <ul class="csul csul2">
                            ${allList}
                        </ul>
                    </div>
                `
            }else if(index==1){
                let allList=''
                item.filtrateOptionList.forEach((items, index1) => {
                    if (index1 == 0) {
                        allList += `
                        <li data-sort="${items.paramValue}" onclick="getValue3()" class="li2Active">${items.name}</li>
                    `
                    } else {
                        allList += `
                        <li data-sort="${items.paramValue}" onclick="getValue3()">${items.name}</li>
                    `
                    }
                })
                div1.innerHTML+=`
                    <div class="everyContent">
                        <p class="csT">${item.name}</p>
                        <ul class="csul csul3">
                            ${allList}
                        </ul>
                    </div>
                `
            }else{
                let allList=''
                item.filtrateOptionList.forEach((items, index1) => {
                    if (index1 == 0) {
                        allList += `
                        <li data-sort="${items.paramValue}" onclick="getValue4()" class="li2Active">${items.name}</li>
                    `
                    } else {
                        allList += `
                        <li data-sort="${items.paramValue}" onclick="getValue4()">${items.name}</li>
                    `
                    }
                })
                 div1.innerHTML+=`
                    <div class="everyContent">
                        <p class="csT">${item.name}</p>
                        <ul class="csul csul4">
                            ${allList}
                        </ul>
                    </div>
                `
            }
        })
        res1.result.sortOptionList.forEach((item,index)=>{
            if(index==0){
                div2.innerHTML+=`
                     <li onclick="getValue5()" data-sort="${item.paramValue}" class="active3">${item.name}</li> 
                `
            }else{
                div2.innerHTML+=`
                     <li onclick="getValue5()" data-sort="${item.paramValue}">${item.name}</li> 
                `
            }
        })
    })
}
changeContentMan()

const ul2=document.querySelector('.bookList')
let 
const getList=(worksTypes=0,bookType=0,subWorksTypes=0,totalWord=0,serialStatus=9,vip=9,categoryId=0,categoryPid=0,naodongFilter=0)=>{
    const queryParams = new URLSearchParams({
        worksTypes,
        bookType,
        subWorksTypes,
        totalWord,
        serialStatus,
        vip,
        categoryId,
        categoryPid,
        naodongFilter
    })
    fetch(`https://www.zongheng.com/api2/catefine/storeSearch?${queryParams}`,{
        method:'POST'
    }).then(res=>res.json()).then(res1=>{
        console.log(res1)
        res1.result.bookList.forEach(item=>{
            ul2.innerHTML+=`
                <li>
                    <div class="left-imgbox">
                        <img src="${item.picUrl}" alt="">
                    </div>
                    <div class="right-txt">
                        <p class="title">${item.name}</p>
                        <p class="sort"><span>${item.authorName}</span>·<span>${item.categoryName}</span>·连载·${Math.floor(item.totalWords/10000)}万字</p>
                        <p class="intro">
                            ${item.description}
                        </p>
                        <div class="bottom-txt">
                            <p class="zhanjie">
                                ${item.theNewChapter}
                            </p>
                            <p class="time">${item.orderColumnInfo}</p>
                        </div>
                    </div>
                </li>
            `
        })
        
    }).catch(err=>{
        console.log(err)
    })
}
getList()
const getValue1=()=>{
    const li1=document.querySelectorAll('.csul1 li')
    li1.forEach(item=>{
        item.classList.remove('li2Active')
    })
    event.target.classList.add('li2Active')
}
const getValue2=()=>{
    const li2=document.querySelectorAll('.csul2 li')
     li2.forEach(item=>{
        item.classList.remove('li2Active')
    })
    event.target.classList.add('li2Active')
}
const getValue3=()=>{
    const li2=document.querySelectorAll('.csul3 li')
     li2.forEach(item=>{
        item.classList.remove('li2Active')
    })
    event.target.classList.add('li2Active')
}
const getValue4=()=>{
    const li2=document.querySelectorAll('.csul4 li')
     li2.forEach(item=>{
        item.classList.remove('li2Active')
    })
    event.target.classList.add('li2Active')
}
const getValue5=()=>{
     const li2=document.querySelectorAll('.rcul li')
     li2.forEach(item=>{
        item.classList.remove('active3')
    })
    event.target.classList.add('active3')
}
const scrollToTopBtn=document.querySelector('.returnTop')
scrollToTopBtn.addEventListener('click', function() {
            window.scrollTo({
                top: 0,
                behavior: 'smooth'
            })
        })